import config
import time
from dateutil import rrule
from datetime import datetime
from bubbles.NEMTCountdownQuery import NEMTCountdownQuery
from utils import *


def register():
	return CET46Countdown()


class CET46Countdown:
	def __init__(self):
		self.type = 'active'
		self.countdown = NEMTCountdownQuery()
		self.last = 0
		self.help = \
'''四六级倒计时提醒：
	用法：无（自动）
	将在每天6点自动提醒距离下一次四六级笔试的天数。'''

	def run(self, gum):
		now = time.time()
		if now - self.last <= config.bubbles.NEMTCountdown.gap \
				or time.localtime(now).tm_hour != config.bubbles.NEMTCountdown.hour:
			return
		self.last = now

		chain = MsgChain()
		chain.addPlain(f'糖糖提醒您，距离四六级还有{self.calc()}天。数据仅供参考，如有变动请参考相关通知。')

		sendFriendsAndGroups(chain, config.bubbles.NEMTCountdown.friends, config.bubbles.NEMTCountdown.groups)
